package qf.dao.daoImpl;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import qf.dao.RecordDao;
import qf.pojo.Page;
import qf.pojo.Record;
import qf.utils.DBUtil;

import java.sql.SQLException;
import java.util.List;

/**
 * @author 86198
 * @version V1.0
 * @Project Java_qf
 * @Package qf.dao.daoImpl
 * @Description:
 * @Date 2022/5/27 14:59
 */
public class RecordDaoImpl implements RecordDao {
    private QueryRunner qr = new QueryRunner(DBUtil.getDateSource());


    public List<Record> selectAllRecords(Page page) {
        String sql = "select * from record limit ?,?";
        try {
            return qr.query(sql, new BeanListHandler<Record>(Record.class), page.getStartPages(), page.getPageSize());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public int FindCountAll(Page page) {
        String sql = "select count(*) from record";
        try {
            long query = qr.query(sql, new ScalarHandler<Long>());
            return (int)query;
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return 0;
    }
}
